home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / ms.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  5KB  |  189 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; ms.c : multisound & drum sound windows
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <gemfast.h>
  24. #include "gm/gem_man.h"
  25. #include "eked-m1.h"
  26. #include "defs.h"
  27. #include "types.h"
  28. #include "externs.h"
  29.  
  30. static BYTE sample[] = {
  31.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  32.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.   0, 0, 0, 0, 0, 0, 0, 0, 33, 33,
  35.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38.   0, 99, 0, 0, 0, 0, 0, 0, 0, 0,
  39.   0, 0, 0, 0, 0, 0, 30, 0, 0, 0,
  40.   0, 0, 0, 99, 99, 99, 99, 99, 30, 0,
  41.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  42.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  43.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  44.   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  45.   0, 0, 0
  46. };
  47.  
  48. static int point_size = 8;
  49. static int ms_handle = -1;
  50. static ms_rows = 20;
  51. static int ms_selected;
  52.  
  53. static char *ms_content(int x, int y, long usr_val);
  54. static int ms_action(int handle, E_TYPE type, void *event,
  55.                      int x_pos, int y_pos, long usr_val);
  56.  
  57. void ms_size(int size)
  58. {
  59.   point_size = size;
  60. }
  61.  
  62. void ms_window()
  63. {
  64.   if(ms_handle < 0){
  65.     ms_handle = lm_open((GRECT *) NULL, "Multisounds",
  66.                         5, ms_rows, point_size, 1 + point_size / 4,
  67.                         13, point_size, WHITE, GREEN,
  68.                 ms_content, ms_action, 0L);
  69.     if(ms_handle < 0)
  70.       fm_alert(1, ms_handle == OUT_OF_MEMORY ? WINDMEM_ALERT : WINDOW_ALERT);
  71.     ms_selected = NIL;
  72.   }
  73.   else
  74.     wm_topped(ms_handle);
  75. }
  76.  
  77. static char *ms_content(int x, int y, long usr_val)
  78. {
  79.   int n = ms_rows * x + y;
  80.   static char text[15];
  81.  
  82.   text[0] = (n == ms_selected);
  83.   text[1] = '0' + n / 10;
  84.   text[2] = '0' + n % 10;
  85.   text[3] = ' ';
  86.   (void) korg2str(text + 4, multisound[n], (size_t) 10);
  87.   return text;
  88. }
  89.  
  90. static int ms_action(int handle, E_TYPE type, void *event,
  91.                      int x_pos, int y_pos, long usr_val)
  92. {
  93.   int s, t;
  94.   CLICK *c;
  95.  
  96.   switch(type){
  97.   case E_CLEANUP:
  98.     m1_ctrl(handle, EXITING, 0, 0, (BYTE *) NULL);
  99.     ms_handle = -1;
  100.     break;
  101.   case E_USER:
  102.     if(((int *) event)[0] == M1_CTRL_LOST){
  103.       t = ms_selected;
  104.       if(t != NIL){
  105.         ms_selected = NIL;
  106.         lm_update(handle, t / ms_rows, t % ms_rows);
  107.       }
  108.     }
  109.     break;
  110.   case E_CLICK:
  111.     c = (CLICK *) event;
  112.     s = ms_rows * c->m_x + c->m_y;
  113.     if(s != ms_selected){
  114.       t = ms_selected;
  115.       ms_selected = s;
  116.       if(t != NIL)
  117.         lm_update(handle, t / ms_rows, t % ms_rows);
  118.       lm_update(handle, c->m_x, c->m_y);
  119.       strncpy(sample, multisound[s], (size_t) 10);
  120.       sample[12] = s;
  121.       m1_ctrl(handle, FORCE_NR | FORCE_DATA, PROG_MODE,
  122.               (s < 100) ? s : 0, sample);
  123.     }
  124.     break;
  125.   }
  126.   return R_NORMAL;
  127. }
  128.  
  129. static int ds_handle = -1;
  130. static ds_rows = 11;
  131. static int ds_selected;
  132.  
  133. static char *ds_content(int x, int y, long usr_val);
  134. static int ds_action(int handle, E_TYPE type, void *event,
  135.                      int x_pos, int y_pos, long usr_val);
  136.  
  137. void ds_window()
  138. {
  139.   if(ds_handle < 0){
  140.     ds_handle = lm_open((GRECT *) NULL, "Drum Sounds",
  141.                         4, ds_rows, point_size, 1 + point_size / 4,
  142.                         13, point_size, WHITE, MAGENTA,
  143.                 ds_content, ds_action, 0L);
  144.     if(ds_handle < 0)
  145.       fm_alert(1, ds_handle == OUT_OF_MEMORY ? WINDMEM_ALERT : WINDOW_ALERT);
  146.     ds_selected = NIL;
  147.   }
  148.   else
  149.     wm_topped(ds_handle);
  150. }
  151.  
  152. static char *ds_content(int x, int y, long usr_val)
  153. {
  154.   int n = 1 + ds_rows * x + y;
  155.   static char text[15];
  156.  
  157.   text[0] = (n == ds_selected);
  158.   text[1] = '0' + n / 10;
  159.   text[2] = '0' + n % 10;
  160.   text[3] = ' ';
  161.   (void) korg2str(text + 4, drum_sound[n], (size_t) 10);
  162.   return text;
  163. }
  164.  
  165. static int ds_action(int handle, E_TYPE type, void *event,
  166.                      int x_pos, int y_pos, long usr_val)
  167. {
  168.   int s, t;
  169.   CLICK *c;
  170.  
  171.   switch(type){
  172.   case E_CLEANUP:
  173.     ds_handle = -1;
  174.     break;
  175.   case E_CLICK:
  176.     c = (CLICK *) event;
  177.     s = ds_rows * c->m_x + c->m_y;
  178.     if(s != ds_selected){
  179.       t = ds_selected;
  180.       ds_selected = s;
  181.       if(t != NIL)
  182.         lm_update(handle, t / ds_rows, t % ds_rows);
  183.       lm_update(handle, c->m_x, c->m_y);
  184.     }
  185.     break;
  186.   }
  187.   return R_NORMAL;
  188. }
  189.